package vesko1;

import java.util.Calendar;
import java.util.Date;
import javax.swing.table.TableCellRenderer;
import org.jdesktop.application.Action;
import org.jdesktop.application.FrameView;
import vesko1.model.InsuranceDAO;
import vesko1.model.Person;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import org.jdesktop.application.SingleFrameApplication;
import vesko1.model.BackupAndRestore;
import vesko1.model.CarDAO;
import vesko1.model.*;
        

public class Vesko1View extends FrameView {

    private final String[] COL_NAMES_FOR_COMPANY_SEARCH =  new String[]{
                    "Компания","Застраховано лице", "Полица номер","Срок","Премия" };
    
    private final String[] COL_NAMES_FOR_SALES_SEARCH =  new String[]{
                    "Полица номер","Стикер номер","Вноска","Сключена на","Валидна от","Валидна до","Брой вноски","Премия", };

    private Person newUsualDriver;
    private String[] peopleMails;
    private String documentPath;
    private ArrayList<Object> documents;

    public Vesko1View(SingleFrameApplication app) {
        super(app);

        initComponents();

        validFrom.setModel(new SpinnerDateModel(new Date(), null, null,
                Calendar.DAY_OF_MONTH));
        validTo.setModel(new SpinnerDateModel(new Date(), null, null,
                Calendar.DAY_OF_MONTH));
        dateOfContract.setModel(new SpinnerDateModel(new Date(), null, null,
                Calendar.DAY_OF_MONTH));
        
        searchFromDate.setModel(new SpinnerDateModel(new Date(), null, null,
                Calendar.DAY_OF_MONTH));
        searchТоDate.setModel(new SpinnerDateModel(new Date(), null, null,
                Calendar.DAY_OF_MONTH));
        salesSearchFromDate.setModel(new SpinnerDateModel(new Date(), null, null,
                Calendar.DAY_OF_MONTH));
        salesSearchToDate.setModel(new SpinnerDateModel(new Date(), null, null,
                Calendar.DAY_OF_MONTH));
        
        validFrom.setEditor(new JSpinner.DateEditor(validFrom, "yyyy-MM-dd"));
        validTo.setEditor(new JSpinner.DateEditor(validTo, "yyyy-MM-dd"));
        dateOfContract.setEditor(new JSpinner.DateEditor(dateOfContract, "yyyy-MM-dd"));
        
        searchFromDate.setEditor(new JSpinner.DateEditor(searchFromDate, "yyyy-MM-dd"));
        searchТоDate.setEditor(new JSpinner.DateEditor(searchТоDate, "yyyy-MM-dd"));
        salesSearchFromDate.setEditor(new JSpinner.DateEditor(salesSearchFromDate, "yyyy-MM-dd"));
        salesSearchToDate.setEditor(new JSpinner.DateEditor(salesSearchToDate, "yyyy-MM-dd"));
    }

    @Action
    public void addNewPolicy() {
        Person owner = new Person(egn.getText(), fullName.getText(), (personType.getSelectedIndex() == 0),
                city.getText(), adress.getText(), phone.getText(), email.getText(), PTP.getSelectedIndex() == 1);
        PersonDAO.addNewPerson(owner);

        if (newUsualDriver != null && newUsualDriver.getEgn() == null
                && !newUsualDriver.getEgn().equals(owner.getEgn())) {
            PersonDAO.addNewPerson(newUsualDriver);
        } else {
            newUsualDriver = owner;
        }

        CarDAO.addNewCar(new Car(regNumber.getText(), ramaNumber.getText(), marka.getText(),
                model.getText(), Float.valueOf(cubics.getText()), Float.valueOf(tonage.getText()),
                Integer.valueOf(numberOfSeats.getText()), Integer.valueOf(yearMade.getText()),
                newUsualDriver, owner));

        final int insertedId = InsuranceDAO.addNewInsurance(new Insurance(regNumber.getText(),
                (typeOfPayment.getSelectedIndex() - 1) * 2,
                (Date) dateOfContract.getValue(),
                false,
                companyName.getText(),
                policy.getText(),   
                (Date) validFrom.getValue(),
                (Date) validTo.getValue(),
                greenCardNumber.getText(),
                Float.valueOf(premium.getText()),
                Float.valueOf(grajdFond.getText()),
                stickerNumber.getText()), documentPath);

        if (insertedId > 0 && typeOfPayment.getSelectedIndex() > 0) {
            EventQueue.invokeLater(new Runnable() {

                @Override
                public void run() {
                    new InstallmentsForm(egn.getText(), insertedId, Float.valueOf(premium.getText()), 
                                        (int)Math.pow(2,typeOfPayment.getSelectedIndex())).setVisible(true);
                }
            });

        }

    }

    private void handleLateInsurancesTab() {
        final int RESULT_COLS = 7;
        final Object[][] tableData = InsuranceDAO.getLateInsurances();
        peopleMails = new String[tableData.length];
        documents = new ArrayList<Object>();
        for (int i = 0; i < tableData.length; i++) {
            peopleMails[i] = (String) tableData[i][RESULT_COLS - 2];
            documents.add(tableData[i][RESULT_COLS - 1]);
        }
        
        
		expiringPolicies.setModel(new javax.swing.table.DefaultTableModel(tableData,
                new String[]{
                    "Застраховано лице", "Застрахователна компания", "Полица N:", "Падеж", "Премия", "Изпрати eмейл"
                }));
        expiringPolicies.getColumn("Изпрати eмейл").setCellRenderer(new ButtonRenderer());
        expiringPolicies.getColumn("Изпрати eмейл").setCellEditor(
                new ButtonEditor(new JCheckBox()));
     }

    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        tabbedPane = new javax.swing.JTabbedPane();
        expiringPoliciesPanel = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        expiringPolicies = new javax.swing.JTable()
        {

            public Component prepareRenderer(
                    TableCellRenderer renderer, int row, int column) {
				Component c = super.prepareRenderer(renderer, row, column);
				final int VALID_TO_COLUMN = 3;
				if ( column == VALID_TO_COLUMN) {
					int newRow = convertRowIndexToModel(row);
					Date validTo = null;
					if ( getModel() != null && getModel().getValueAt(newRow, column) != null )
						validTo = (Date)getModel().getValueAt(newRow, column);
					if (validTo != null && new Date().after(validTo)) 
						c.setForeground(Color.RED);
			    }
				else
					c.setForeground(Color.BLACK);
				
                return c;
            }
        };

        reportsPanel = new javax.swing.JPanel();
        dailyReportButton = new javax.swing.JButton();
        weeklyReportButton = new javax.swing.JButton();
        monthlyReportButton = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        reportTable = new javax.swing.JTable();
        backupPanel = new javax.swing.JPanel();
        SaveToDBButton = new javax.swing.JButton();
        restoreFromButton = new javax.swing.JButton();
        saveTo = new javax.swing.JTextField();
        getSavingDBDir = new javax.swing.JButton();
        restoreFrom = new javax.swing.JTextField();
        getRestoringDBDir = new javax.swing.JButton();
        AddNewPolicyPanel = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        contractor = new javax.swing.JTextField();
        policy = new javax.swing.JTextField();
        validFrom = new javax.swing.JSpinner();
        validTo = new javax.swing.JSpinner();
        greenCardNumber = new javax.swing.JTextField();
        regNumber = new javax.swing.JTextField();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel10 = new javax.swing.JLabel();
        ramaNumber = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        model = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        cubics = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        tonage = new javax.swing.JTextField();
        jLabel14 = new javax.swing.JLabel();
        numberOfSeats = new javax.swing.JTextField();
        jSeparator5 = new javax.swing.JSeparator();
        jLabel15 = new javax.swing.JLabel();
        email = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        phone = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        adress = new javax.swing.JTextField();
        egn = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        fullName = new javax.swing.JTextField();
        personType = new javax.swing.JComboBox();
        jLabel21 = new javax.swing.JLabel();
        PTP = new javax.swing.JComboBox();
        jSeparator6 = new javax.swing.JSeparator();
        jButton1 = new javax.swing.JButton();
        resetFields = new javax.swing.JButton();
        jLabel22 = new javax.swing.JLabel();
        dateOfContract = new javax.swing.JSpinner();
        jSeparator7 = new javax.swing.JSeparator();
        addButton = new javax.swing.JButton();
        typeOfPayment = new javax.swing.JComboBox();
        jLabel23 = new javax.swing.JLabel();
        companyName = new javax.swing.JTextField();
        gFondLabel = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel28 = new javax.swing.JLabel();
        jLabel29 = new javax.swing.JLabel();
        premium = new javax.swing.JTextField();
        grajdFond = new javax.swing.JTextField();
        jLabel30 = new javax.swing.JLabel();
        city = new javax.swing.JTextField();
        setUsualDriver = new javax.swing.JButton();
        jLabel31 = new javax.swing.JLabel();
        marka = new javax.swing.JTextField();
        jLabel32 = new javax.swing.JLabel();
        yearMade = new javax.swing.JTextField();
        jLabel33 = new javax.swing.JLabel();
        stickerNumber = new javax.swing.JTextField();
        AddScannedDocButton = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        queryByCompanyResults = new javax.swing.JTable();
        company = new javax.swing.JTextField();
        searchByCompanyButton = new javax.swing.JButton();
        companyNameLabel = new javax.swing.JLabel();
        excelExportBrokerSearch = new javax.swing.JButton();
        jLabel25 = new javax.swing.JLabel();
        jLabel26 = new javax.swing.JLabel();
        searchFromDate = new javax.swing.JSpinner();
        searchТоDate = new javax.swing.JSpinner();
        queriesPanel = new javax.swing.JPanel();
        jLabel24 = new javax.swing.JLabel();
        driverEgn = new javax.swing.JTextField();
        searchButton = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        queryResults = new javax.swing.JTable();
        jPanel3 = new javax.swing.JPanel();
        jButton3 = new javax.swing.JButton();
        jLabel27 = new javax.swing.JLabel();
        searchByCompanyButton1 = new javax.swing.JButton();
        companyNameLabel1 = new javax.swing.JLabel();
        salesSearchCompany = new javax.swing.JTextField();
        jScrollPane5 = new javax.swing.JScrollPane();
        salesResults = new javax.swing.JTable();
        salesSearchToDate = new javax.swing.JSpinner();
        jLabel34 = new javax.swing.JLabel();
        salesSearchFromDate = new javax.swing.JSpinner();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();

        mainPanel.setName("mainPanel"); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 100, Short.MAX_VALUE)
        );

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(vesko1.Vesko1App.class).getContext().getResourceMap(Vesko1View.class);
        tabbedPane.setBackground(resourceMap.getColor("tabbedPane.background")); // NOI18N
        tabbedPane.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        tabbedPane.setFont(resourceMap.getFont("tabbedPane.font")); // NOI18N
        tabbedPane.setName("tabbedPane"); // NOI18N
        tabbedPane.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                tabbedPaneStateChanged(evt);
            }
        });

        expiringPoliciesPanel.setName("expiringPoliciesPanel"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        expiringPolicies.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        expiringPolicies.setName("expiringPolicies"); // NOI18N
        jScrollPane1.setViewportView(expiringPolicies);

        javax.swing.GroupLayout expiringPoliciesPanelLayout = new javax.swing.GroupLayout(expiringPoliciesPanel);
        expiringPoliciesPanel.setLayout(expiringPoliciesPanelLayout);
        expiringPoliciesPanelLayout.setHorizontalGroup(
            expiringPoliciesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 1082, Short.MAX_VALUE)
        );
        expiringPoliciesPanelLayout.setVerticalGroup(
            expiringPoliciesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 348, Short.MAX_VALUE)
        );

        tabbedPane.addTab(resourceMap.getString("expiringPoliciesPanel.TabConstraints.tabTitle"), expiringPoliciesPanel); // NOI18N

        reportsPanel.setName("reportsPanel"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(vesko1.Vesko1App.class).getContext().getActionMap(Vesko1View.class, this);
        dailyReportButton.setAction(actionMap.get("makeDailyReport")); // NOI18N
        dailyReportButton.setText(resourceMap.getString("dailyReportButton.text")); // NOI18N
        dailyReportButton.setName("dailyReportButton"); // NOI18N

        weeklyReportButton.setText(resourceMap.getString("weeklyReportButton.text")); // NOI18N
        weeklyReportButton.setName("weeklyReportButton"); // NOI18N
        weeklyReportButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                weeklyReportButtonActionPerformed(evt);
            }
        });

        monthlyReportButton.setText(resourceMap.getString("monthlyReportButton.text")); // NOI18N
        monthlyReportButton.setName("monthlyReportButton"); // NOI18N
        monthlyReportButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                monthlyReportButtonActionPerformed(evt);
            }
        });

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        reportTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Номер на полица", "Номер на стикер", "Премия", "2% от премията", "Граждански фонд", "Общо"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.Float.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        reportTable.setName("reportTable"); // NOI18N
        jScrollPane2.setViewportView(reportTable);
        reportTable.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("reportTable.columnModel.title0")); // NOI18N
        reportTable.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("reportTable.columnModel.title1")); // NOI18N
        reportTable.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("reportTable.columnModel.title2")); // NOI18N
        reportTable.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("reportTable.columnModel.title3")); // NOI18N
        reportTable.getColumnModel().getColumn(4).setHeaderValue(resourceMap.getString("reportTable.columnModel.title4")); // NOI18N
        reportTable.getColumnModel().getColumn(5).setHeaderValue(resourceMap.getString("reportTable.columnModel.title5")); // NOI18N

        javax.swing.GroupLayout reportsPanelLayout = new javax.swing.GroupLayout(reportsPanel);
        reportsPanel.setLayout(reportsPanelLayout);
        reportsPanelLayout.setHorizontalGroup(
            reportsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(reportsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(reportsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(monthlyReportButton, javax.swing.GroupLayout.PREFERRED_SIZE, 308, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(weeklyReportButton, javax.swing.GroupLayout.PREFERRED_SIZE, 308, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(dailyReportButton, javax.swing.GroupLayout.PREFERRED_SIZE, 308, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 736, Short.MAX_VALUE)
                .addContainerGap())
        );
        reportsPanelLayout.setVerticalGroup(
            reportsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(reportsPanelLayout.createSequentialGroup()
                .addGroup(reportsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(reportsPanelLayout.createSequentialGroup()
                        .addGap(33, 33, 33)
                        .addComponent(dailyReportButton)
                        .addGap(36, 36, 36)
                        .addComponent(weeklyReportButton)
                        .addGap(35, 35, 35)
                        .addComponent(monthlyReportButton))
                    .addGroup(reportsPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 306, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(31, Short.MAX_VALUE))
        );

        tabbedPane.addTab(resourceMap.getString("reportsPanel.TabConstraints.tabTitle"), reportsPanel); // NOI18N

        backupPanel.setName("backupPanel"); // NOI18N

        SaveToDBButton.setAction(actionMap.get("saveDB")); // NOI18N
        SaveToDBButton.setText(resourceMap.getString("SaveToDBButton.text")); // NOI18N
        SaveToDBButton.setName("SaveToDBButton"); // NOI18N

        restoreFromButton.setAction(actionMap.get("restoreDB")); // NOI18N
        restoreFromButton.setText(resourceMap.getString("restoreFromButton.text")); // NOI18N
        restoreFromButton.setName("restoreFromButton"); // NOI18N

        saveTo.setText(resourceMap.getString("saveTo.text")); // NOI18N
        saveTo.setName("saveTo"); // NOI18N

        getSavingDBDir.setAction(actionMap.get("selectSaveDBLocation")); // NOI18N
        getSavingDBDir.setText(resourceMap.getString("getSavingDBDir.text")); // NOI18N
        getSavingDBDir.setName("getSavingDBDir"); // NOI18N

        restoreFrom.setText(resourceMap.getString("restoreFrom.text")); // NOI18N
        restoreFrom.setName("restoreFrom"); // NOI18N

        getRestoringDBDir.setAction(actionMap.get("setRestoreDBLocation")); // NOI18N
        getRestoringDBDir.setText(resourceMap.getString("getRestoringDBDir.text")); // NOI18N
        getRestoringDBDir.setName("getRestoringDBDir"); // NOI18N

        javax.swing.GroupLayout backupPanelLayout = new javax.swing.GroupLayout(backupPanel);
        backupPanel.setLayout(backupPanelLayout);
        backupPanelLayout.setHorizontalGroup(
            backupPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(backupPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(backupPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(restoreFromButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(SaveToDBButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(backupPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(backupPanelLayout.createSequentialGroup()
                        .addComponent(saveTo, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(getSavingDBDir))
                    .addGroup(backupPanelLayout.createSequentialGroup()
                        .addComponent(restoreFrom, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(getRestoringDBDir)))
                .addContainerGap(626, Short.MAX_VALUE))
        );
        backupPanelLayout.setVerticalGroup(
            backupPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(backupPanelLayout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addGroup(backupPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(SaveToDBButton)
                    .addComponent(saveTo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(getSavingDBDir))
                .addGap(28, 28, 28)
                .addGroup(backupPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(restoreFromButton)
                    .addComponent(restoreFrom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(getRestoringDBDir))
                .addContainerGap(239, Short.MAX_VALUE))
        );

        tabbedPane.addTab(resourceMap.getString("backupPanel.TabConstraints.tabTitle"), backupPanel); // NOI18N

        AddNewPolicyPanel.setName("AddNewPolicyPanel"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        contractor.setText(resourceMap.getString("contractor.text")); // NOI18N
        contractor.setName("contractor"); // NOI18N

        policy.setName("policy"); // NOI18N

        validFrom.setModel(new javax.swing.SpinnerDateModel(new java.util.Date(1359582316307L), null, null, java.util.Calendar.MONTH));
        validFrom.setName("validFrom"); // NOI18N

        validTo.setModel(new javax.swing.SpinnerDateModel(new java.util.Date(1358689280220L), null, null, java.util.Calendar.MONTH));
        validTo.setName("validTo"); // NOI18N

        greenCardNumber.setName("greenCardNumber"); // NOI18N

        regNumber.setName("regNumber"); // NOI18N

        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);
        jSeparator1.setName("jSeparator1"); // NOI18N

        jLabel10.setText(resourceMap.getString("jLabel10.text")); // NOI18N
        jLabel10.setName("jLabel10"); // NOI18N

        ramaNumber.setName("ramaNumber"); // NOI18N

        jLabel11.setText(resourceMap.getString("jLabel11.text")); // NOI18N
        jLabel11.setName("jLabel11"); // NOI18N

        model.setName("model"); // NOI18N

        jLabel12.setText(resourceMap.getString("jLabel12.text")); // NOI18N
        jLabel12.setName("jLabel12"); // NOI18N

        cubics.setName("cubics"); // NOI18N

        jLabel13.setText(resourceMap.getString("jLabel13.text")); // NOI18N
        jLabel13.setName("jLabel13"); // NOI18N

        tonage.setName("tonage"); // NOI18N

        jLabel14.setText(resourceMap.getString("jLabel14.text")); // NOI18N
        jLabel14.setName("jLabel14"); // NOI18N

        numberOfSeats.setName("numberOfSeats"); // NOI18N

        jSeparator5.setOrientation(javax.swing.SwingConstants.VERTICAL);
        jSeparator5.setName("jSeparator5"); // NOI18N

        jLabel15.setText(resourceMap.getString("jLabel15.text")); // NOI18N
        jLabel15.setName("jLabel15"); // NOI18N

        email.setName("email"); // NOI18N

        jLabel16.setText(resourceMap.getString("jLabel16.text")); // NOI18N
        jLabel16.setName("jLabel16"); // NOI18N

        jLabel17.setText(resourceMap.getString("jLabel17.text")); // NOI18N
        jLabel17.setName("jLabel17"); // NOI18N

        phone.setName("phone"); // NOI18N

        jLabel18.setText(resourceMap.getString("jLabel18.text")); // NOI18N
        jLabel18.setName("jLabel18"); // NOI18N

        adress.setName("adress"); // NOI18N

        egn.setName("egn"); // NOI18N

        jLabel19.setText(resourceMap.getString("jLabel19.text")); // NOI18N
        jLabel19.setName("jLabel19"); // NOI18N

        jLabel20.setText(resourceMap.getString("jLabel20.text")); // NOI18N
        jLabel20.setName("jLabel20"); // NOI18N

        fullName.setName("fullName"); // NOI18N

        personType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Физическо лице", "Юридическо лице" }));
        personType.setName("personType"); // NOI18N

        jLabel21.setText(resourceMap.getString("jLabel21.text")); // NOI18N
        jLabel21.setName("jLabel21"); // NOI18N

        PTP.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Не", "Да" }));
        PTP.setToolTipText(resourceMap.getString("PTP.toolTipText")); // NOI18N
        PTP.setName("PTP"); // NOI18N

        jSeparator6.setName("jSeparator6"); // NOI18N

        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N

        resetFields.setAction(actionMap.get("clearAll")); // NOI18N
        resetFields.setText(resourceMap.getString("resetFields.text")); // NOI18N
        resetFields.setName("resetFields"); // NOI18N

        jLabel22.setText(resourceMap.getString("jLabel22.text")); // NOI18N
        jLabel22.setName("jLabel22"); // NOI18N

        dateOfContract.setModel(new javax.swing.SpinnerDateModel());
        dateOfContract.setName("dateOfContract"); // NOI18N

        jSeparator7.setOrientation(javax.swing.SwingConstants.VERTICAL);
        jSeparator7.setName("jSeparator7"); // NOI18N

        addButton.setAction(actionMap.get("addNewPolicy")); // NOI18N
        addButton.setText(resourceMap.getString("addButton.text")); // NOI18N
        addButton.setName("addButton"); // NOI18N

        typeOfPayment.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Еднократно", "2 Вноски", "4 Вноски" }));
        typeOfPayment.setName("typeOfPayment"); // NOI18N

        jLabel23.setText(resourceMap.getString("jLabel23.text")); // NOI18N
        jLabel23.setName("jLabel23"); // NOI18N

        companyName.setText(resourceMap.getString("companyName.text")); // NOI18N
        companyName.setName("companyName"); // NOI18N

        gFondLabel.setFont(resourceMap.getFont("gFondLabel.font")); // NOI18N
        gFondLabel.setText(resourceMap.getString("gFondLabel.text")); // NOI18N
        gFondLabel.setToolTipText(resourceMap.getString("gFondLabel.toolTipText")); // NOI18N
        gFondLabel.setName("gFondLabel"); // NOI18N

        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel28.setText(resourceMap.getString("jLabel28.text")); // NOI18N
        jLabel28.setName("jLabel28"); // NOI18N

        jLabel29.setText(resourceMap.getString("jLabel29.text")); // NOI18N
        jLabel29.setName("jLabel29"); // NOI18N

        premium.setText(resourceMap.getString("premium.text")); // NOI18N
        premium.setName("premium"); // NOI18N

        grajdFond.setText(resourceMap.getString("grajdFond.text")); // NOI18N
        grajdFond.setName("grajdFond"); // NOI18N

        jLabel30.setText(resourceMap.getString("jLabel30.text")); // NOI18N
        jLabel30.setName("jLabel30"); // NOI18N

        city.setText(resourceMap.getString("city.text")); // NOI18N
        city.setName("city"); // NOI18N

        setUsualDriver.setAction(actionMap.get("setUsualDriver")); // NOI18N
        setUsualDriver.setText(resourceMap.getString("setUsualDriver.text")); // NOI18N
        setUsualDriver.setName("setUsualDriver"); // NOI18N

        jLabel31.setText(resourceMap.getString("jLabel31.text")); // NOI18N
        jLabel31.setName("jLabel31"); // NOI18N

        marka.setName("marka"); // NOI18N

        jLabel32.setText(resourceMap.getString("jLabel32.text")); // NOI18N
        jLabel32.setName("jLabel32"); // NOI18N

        yearMade.setText(resourceMap.getString("yearMade.text")); // NOI18N
        yearMade.setName("yearMade"); // NOI18N

        jLabel33.setText(resourceMap.getString("jLabel33.text")); // NOI18N
        jLabel33.setName("jLabel33"); // NOI18N

        stickerNumber.setText(resourceMap.getString("stickerNumber.text")); // NOI18N
        stickerNumber.setName("stickerNumber"); // NOI18N

        AddScannedDocButton.setAction(actionMap.get("getScannedDocument")); // NOI18N
        AddScannedDocButton.setText(resourceMap.getString("AddScannedDocButton.text")); // NOI18N
        AddScannedDocButton.setName("AddScannedDocButton"); // NOI18N

        javax.swing.GroupLayout AddNewPolicyPanelLayout = new javax.swing.GroupLayout(AddNewPolicyPanel);
        AddNewPolicyPanel.setLayout(AddNewPolicyPanelLayout);
        AddNewPolicyPanelLayout.setHorizontalGroup(
            AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                        .addGap(1042, 1042, 1042)
                        .addComponent(jLabel8))
                    .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jSeparator6, javax.swing.GroupLayout.DEFAULT_SIZE, 1062, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, AddNewPolicyPanelLayout.createSequentialGroup()
                        .addGap(785, 785, 785)
                        .addComponent(gFondLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 212, Short.MAX_VALUE)
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(75, 75, 75))
                    .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                        .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                                        .addComponent(jLabel22)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(dateOfContract))
                                    .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                                        .addComponent(jLabel5)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(validTo, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                                        .addComponent(jLabel9)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(validFrom, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                                        .addComponent(jLabel3)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(contractor, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                                        .addComponent(jLabel4)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(policy, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                                        .addComponent(jLabel7)
                                        .addGap(33, 33, 33)
                                        .addComponent(companyName, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                                        .addComponent(jLabel2)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(greenCardNumber, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(26, 26, 26)
                                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 17, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                                                .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                    .addComponent(jLabel13)
                                                    .addComponent(jLabel12)
                                                    .addComponent(jLabel14)
                                                    .addComponent(jLabel31)
                                                    .addComponent(jLabel10)
                                                    .addComponent(jLabel11)
                                                    .addComponent(jLabel6))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                                    .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(regNumber, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(ramaNumber, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(model, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(cubics, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(tonage, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(numberOfSeats, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                    .addComponent(marka, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                            .addComponent(jLabel32)))
                                    .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                                        .addGap(35, 35, 35)
                                        .addComponent(yearMade, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(18, 18, 18)
                                .addComponent(jSeparator5, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                                        .addComponent(jLabel18)
                                        .addGap(18, 18, 18)
                                        .addComponent(adress, javax.swing.GroupLayout.PREFERRED_SIZE, 279, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                                        .addComponent(jLabel16)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(email, javax.swing.GroupLayout.PREFERRED_SIZE, 278, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                                        .addComponent(jLabel21)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(PTP, javax.swing.GroupLayout.PREFERRED_SIZE, 252, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                                        .addComponent(jLabel15)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(personType, javax.swing.GroupLayout.PREFERRED_SIZE, 270, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                                        .addComponent(jLabel17)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(phone, javax.swing.GroupLayout.PREFERRED_SIZE, 272, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                                        .addComponent(jLabel20)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(fullName, javax.swing.GroupLayout.PREFERRED_SIZE, 256, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, AddNewPolicyPanelLayout.createSequentialGroup()
                                        .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel30)
                                            .addComponent(jLabel19))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 65, Short.MAX_VALUE)
                                        .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                                                .addComponent(city, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(18, 18, 18)
                                                .addComponent(setUsualDriver, javax.swing.GroupLayout.PREFERRED_SIZE, 171, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addComponent(egn, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(18, 18, 18)))
                                .addGap(0, 0, 0)
                                .addComponent(jSeparator7, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                                .addGap(356, 356, 356)
                                .addComponent(jLabel1)
                                .addGap(199, 199, 199)))
                        .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, AddNewPolicyPanelLayout.createSequentialGroup()
                                .addGap(6, 6, 6)
                                .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel29)
                                    .addComponent(jLabel28))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(premium, javax.swing.GroupLayout.DEFAULT_SIZE, 130, Short.MAX_VALUE)
                                    .addComponent(grajdFond, javax.swing.GroupLayout.DEFAULT_SIZE, 130, Short.MAX_VALUE)))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, AddNewPolicyPanelLayout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel33)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(stickerNumber, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, AddNewPolicyPanelLayout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(addButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE)
                                    .addComponent(resetFields, javax.swing.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE)
                                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, AddNewPolicyPanelLayout.createSequentialGroup()
                                        .addGap(70, 70, 70)
                                        .addComponent(jLabel23)
                                        .addGap(60, 60, 60))
                                    .addComponent(typeOfPayment, 0, 212, Short.MAX_VALUE)
                                    .addComponent(AddScannedDocButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE))))))
                .addContainerGap())
        );
        AddNewPolicyPanelLayout.setVerticalGroup(
            AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, AddNewPolicyPanelLayout.createSequentialGroup()
                                .addGap(91, 91, 91)
                                .addComponent(jLabel23)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(typeOfPayment, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(35, 35, 35)
                                .addComponent(AddScannedDocButton)
                                .addGap(18, 18, 18)
                                .addComponent(resetFields)
                                .addGap(18, 18, 18)
                                .addComponent(addButton))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, AddNewPolicyPanelLayout.createSequentialGroup()
                                .addGap(8, 8, 8)
                                .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                                        .addGap(6, 6, 6)
                                        .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(jLabel6)
                                            .addComponent(regNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                                                .addComponent(jLabel10)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                    .addComponent(jLabel11)
                                                    .addComponent(marka, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                            .addComponent(ramaNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(18, 18, 18)
                                        .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(jLabel31)
                                            .addComponent(model, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(28, 28, 28)
                                        .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                                                .addComponent(jLabel12)
                                                .addGap(18, 18, 18)
                                                .addComponent(jLabel13))
                                            .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                                                .addComponent(cubics, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addComponent(tonage, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(18, 18, 18)
                                                .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                    .addComponent(numberOfSeats, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(jLabel14)))))
                                    .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                                        .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(jLabel7)
                                            .addComponent(companyName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(jLabel3)
                                            .addComponent(contractor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(16, 16, 16)
                                        .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(jLabel4)
                                            .addComponent(policy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(18, 18, 18)
                                        .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(jLabel9)
                                                .addComponent(validFrom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                            .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                                                .addGap(34, 34, 34)
                                                .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                    .addComponent(validTo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(jLabel5))))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(jLabel2)
                                            .addComponent(greenCardNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(dateOfContract, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                            .addComponent(jLabel22)))
                                    .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                                        .addGap(21, 21, 21)
                                        .addComponent(jLabel32)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(yearMade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                                .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jSeparator7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 296, Short.MAX_VALUE)
                                    .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 296, Short.MAX_VALUE)
                                    .addComponent(jSeparator5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 296, Short.MAX_VALUE)
                                    .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                                        .addGap(16, 16, 16)
                                        .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(jLabel19)
                                            .addComponent(egn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(18, 18, 18)
                                        .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(jLabel30)
                                            .addComponent(setUsualDriver)
                                            .addComponent(city, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(jLabel16)
                                            .addComponent(email, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(28, 28, 28)
                                        .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                            .addComponent(jLabel18)
                                            .addComponent(adress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGap(27, 27, 27)
                                        .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                                                .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                    .addComponent(fullName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(jLabel20))
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                    .addComponent(jLabel17)
                                                    .addComponent(phone, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGap(47, 47, 47)
                                                .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                    .addComponent(jLabel15)
                                                    .addComponent(personType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                            .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                                                .addGap(59, 59, 59)
                                                .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                    .addComponent(jLabel21)
                                                    .addComponent(PTP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))))
                                .addGap(20, 20, 20)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                                .addGap(141, 141, 141)
                                .addComponent(jLabel8))
                            .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                                .addGap(63, 63, 63)
                                .addComponent(gFondLabel)
                                .addGap(119, 119, 119)
                                .addComponent(jButton1)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jSeparator6, javax.swing.GroupLayout.PREFERRED_SIZE, 15, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(AddNewPolicyPanelLayout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel28)
                            .addComponent(premium, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel29)
                            .addComponent(grajdFond, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(AddNewPolicyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel33)
                            .addComponent(stickerNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );

        tabbedPane.addTab(resourceMap.getString("AddNewPolicyPanel.TabConstraints.tabTitle"), AddNewPolicyPanel); // NOI18N

        jPanel2.setName("jPanel2"); // NOI18N

        jScrollPane4.setName("jScrollPane4"); // NOI18N

        queryByCompanyResults.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        queryByCompanyResults.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Компания", "Застраховано лице", "Полица номер", "Срок", "Премия"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Object.class, java.lang.Float.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        queryByCompanyResults.setEnabled(false);
        queryByCompanyResults.setName("queryByCompanyResults"); // NOI18N
        jScrollPane4.setViewportView(queryByCompanyResults);
        queryByCompanyResults.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("queryByCompanyResults.columnModel.title6")); // NOI18N
        queryByCompanyResults.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("queryResults.columnModel.title2")); // NOI18N
        queryByCompanyResults.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("queryResults.columnModel.title0")); // NOI18N
        queryByCompanyResults.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("queryByCompanyResults.columnModel.title6")); // NOI18N
        queryByCompanyResults.getColumnModel().getColumn(4).setHeaderValue(resourceMap.getString("queryByCompanyResults.columnModel.title8")); // NOI18N

        company.setName("company"); // NOI18N

        searchByCompanyButton.setAction(actionMap.get("searchByCompany")); // NOI18N
        searchByCompanyButton.setText(resourceMap.getString("searchByCompanyButton.text")); // NOI18N
        searchByCompanyButton.setName("searchByCompanyButton"); // NOI18N

        companyNameLabel.setText(resourceMap.getString("companyNameLabel.text")); // NOI18N
        companyNameLabel.setName("companyNameLabel"); // NOI18N

        excelExportBrokerSearch.setAction(actionMap.get("exportToExcel")); // NOI18N
        excelExportBrokerSearch.setText(resourceMap.getString("excelExportBrokerSearch.text")); // NOI18N
        excelExportBrokerSearch.setName("excelExportBrokerSearch"); // NOI18N

        jLabel25.setText(resourceMap.getString("jLabel25.text")); // NOI18N
        jLabel25.setName("jLabel25"); // NOI18N

        jLabel26.setText(resourceMap.getString("jLabel26.text")); // NOI18N
        jLabel26.setName("jLabel26"); // NOI18N

        searchFromDate.setName("searchFromDate"); // NOI18N

        searchТоDate.setName("searchТоDate"); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(searchByCompanyButton, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(companyNameLabel)
                                    .addComponent(jLabel25)
                                    .addComponent(jLabel26))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(searchFromDate, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)
                                    .addComponent(company, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)
                                    .addComponent(searchТоDate, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)))))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(excelExportBrokerSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 801, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(232, 232, 232))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(companyNameLabel)
                            .addComponent(company, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel25)
                            .addComponent(searchFromDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel26)
                            .addComponent(searchТоDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(searchByCompanyButton)
                        .addGap(18, 18, 18)
                        .addComponent(excelExportBrokerSearch))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(57, Short.MAX_VALUE))
        );

        tabbedPane.addTab(resourceMap.getString("jPanel2.TabConstraints.tabTitle"), jPanel2); // NOI18N

        queriesPanel.setName("queriesPanel"); // NOI18N

        jLabel24.setText(resourceMap.getString("jLabel24.text")); // NOI18N
        jLabel24.setName("jLabel24"); // NOI18N

        driverEgn.setText(resourceMap.getString("driverEgn.text")); // NOI18N
        driverEgn.setName("driverEgn"); // NOI18N

        searchButton.setAction(actionMap.get("searchInstallments")); // NOI18N
        searchButton.setText(resourceMap.getString("searchButton.text")); // NOI18N
        searchButton.setName("searchButton"); // NOI18N

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        queryResults.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        queryResults.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Номер", "Сума за плащане", "Дата за плащане"
            }
        ));
        queryResults.setEnabled(false);
        queryResults.setName("queryResults"); // NOI18N
        jScrollPane3.setViewportView(queryResults);
        queryResults.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("queryResults.columnModel.title0")); // NOI18N
        queryResults.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("queryResults.columnModel.title1")); // NOI18N
        queryResults.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("queryResults.columnModel.title2")); // NOI18N

        javax.swing.GroupLayout queriesPanelLayout = new javax.swing.GroupLayout(queriesPanel);
        queriesPanel.setLayout(queriesPanelLayout);
        queriesPanelLayout.setHorizontalGroup(
            queriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(queriesPanelLayout.createSequentialGroup()
                .addGroup(queriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(queriesPanelLayout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addComponent(jLabel24)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(driverEgn, javax.swing.GroupLayout.DEFAULT_SIZE, 138, Short.MAX_VALUE))
                    .addGroup(queriesPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(searchButton, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 639, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(176, Short.MAX_VALUE))
        );
        queriesPanelLayout.setVerticalGroup(
            queriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(queriesPanelLayout.createSequentialGroup()
                .addGroup(queriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(queriesPanelLayout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addGroup(queriesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel24)
                            .addComponent(driverEgn, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(29, 29, 29)
                        .addComponent(searchButton))
                    .addGroup(queriesPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(57, Short.MAX_VALUE))
        );

        tabbedPane.addTab(resourceMap.getString("queriesPanel.TabConstraints.tabTitle"), queriesPanel); // NOI18N

        jPanel3.setName("jPanel3"); // NOI18N

        jButton3.setAction(actionMap.get("exportToExcel")); // NOI18N
        jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
        jButton3.setName("jButton3"); // NOI18N

        jLabel27.setText(resourceMap.getString("jLabel27.text")); // NOI18N
        jLabel27.setName("jLabel27"); // NOI18N

        searchByCompanyButton1.setAction(actionMap.get("searchSales")); // NOI18N
        searchByCompanyButton1.setText(resourceMap.getString("searchByCompanyButton1.text")); // NOI18N
        searchByCompanyButton1.setName("searchByCompanyButton1"); // NOI18N

        companyNameLabel1.setText(resourceMap.getString("companyNameLabel1.text")); // NOI18N
        companyNameLabel1.setName("companyNameLabel1"); // NOI18N

        salesSearchCompany.setName("salesSearchCompany"); // NOI18N

        jScrollPane5.setName("jScrollPane5"); // NOI18N

        salesResults.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        salesResults.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Полица номер", "Стикер номер", "Вноска", "Сключена на", "Валидна от", "Валидна до", "Брой вноски", "Премия"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Integer.class, java.lang.Float.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        salesResults.setEnabled(false);
        salesResults.setName("salesResults"); // NOI18N
        jScrollPane5.setViewportView(salesResults);
        salesResults.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("queryResults.columnModel.title0")); // NOI18N
        salesResults.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("salesResults.columnModel.title1")); // NOI18N
        salesResults.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("salesResults.columnModel.title2")); // NOI18N
        salesResults.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("queryByCompanyResults.columnModel.title6")); // NOI18N
        salesResults.getColumnModel().getColumn(4).setHeaderValue(resourceMap.getString("salesResults.columnModel.title3")); // NOI18N
        salesResults.getColumnModel().getColumn(5).setHeaderValue(resourceMap.getString("salesResults.columnModel.title4")); // NOI18N
        salesResults.getColumnModel().getColumn(6).setHeaderValue(resourceMap.getString("salesResults.columnModel.title5")); // NOI18N
        salesResults.getColumnModel().getColumn(7).setHeaderValue(resourceMap.getString("queryByCompanyResults.columnModel.title8")); // NOI18N

        salesSearchToDate.setName("salesSearchToDate"); // NOI18N

        jLabel34.setText(resourceMap.getString("jLabel34.text")); // NOI18N
        jLabel34.setName("jLabel34"); // NOI18N

        salesSearchFromDate.setName("salesSearchFromDate"); // NOI18N

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(23, 23, 23)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(searchByCompanyButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanel3Layout.createSequentialGroup()
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(companyNameLabel1)
                                    .addComponent(jLabel27)
                                    .addComponent(jLabel34))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(salesSearchFromDate, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)
                                    .addComponent(salesSearchCompany, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)
                                    .addComponent(salesSearchToDate, javax.swing.GroupLayout.DEFAULT_SIZE, 140, Short.MAX_VALUE)))))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(26, 26, 26)
                .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 793, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(232, 232, 232))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(29, 29, 29)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(companyNameLabel1)
                            .addComponent(salesSearchCompany, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel27)
                            .addComponent(salesSearchFromDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel34)
                            .addComponent(salesSearchToDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addComponent(searchByCompanyButton1)
                        .addGap(18, 18, 18)
                        .addComponent(jButton3))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(57, Short.MAX_VALUE))
        );

        tabbedPane.addTab(resourceMap.getString("jPanel3.TabConstraints.tabTitle"), jPanel3); // NOI18N

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(tabbedPane, javax.swing.GroupLayout.PREFERRED_SIZE, 1091, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(223, 223, 223))
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(37, 37, 37)
                        .addComponent(tabbedPane, javax.swing.GroupLayout.PREFERRED_SIZE, 380, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(61, Short.MAX_VALUE))
        );

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 1430, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 1260, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );

        setComponent(mainPanel);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents

    private void makeReportForXDays(int x) {
        Object[][] data = InsuranceDAO.getInsurancesFromLastXDays(x);
        reportTable.getColumn("Премия").setCellRenderer(new RightTableCellRenderer());
        reportTable.getColumn("2% от премията").setCellRenderer(new RightTableCellRenderer());
        reportTable.getColumn("Граждански фонд").setCellRenderer(new RightTableCellRenderer());
        reportTable.getColumn("Общо").setCellRenderer(new RightTableCellRenderer());
        
        DefaultTableModel tableModel = (DefaultTableModel) reportTable.getModel();
        tableModel.setRowCount(data.length);

        for (int i = 0; i < data.length; i++) {
            for (int j = 0; j < data[i].length; j++) {
                tableModel.setValueAt(data[i][j], i, j);
            }
        }
    }

    private void tabbedPaneStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_tabbedPaneStateChanged
        JTabbedPane sourceTabbedPane = (JTabbedPane) evt.getSource();
        int index = sourceTabbedPane.getSelectedIndex();
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(vesko1.Vesko1App.class).getContext().getResourceMap(Vesko1View.class);

        if (sourceTabbedPane.getTitleAt(index).equals(resourceMap.getString("expiringPoliciesPanel.TabConstraints.tabTitle"))) {
            handleLateInsurancesTab();
        }
    }//GEN-LAST:event_tabbedPaneStateChanged

    private void weeklyReportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_weeklyReportButtonActionPerformed
        makeReportForXDays(7);
    }//GEN-LAST:event_weeklyReportButtonActionPerformed

    private void monthlyReportButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_monthlyReportButtonActionPerformed
        makeReportForXDays(Calendar.getInstance().getActualMaximum(Calendar.DAY_OF_MONTH));
    }//GEN-LAST:event_monthlyReportButtonActionPerformed

    @Action
    public void setUsualDriver() {
        newUsualDriver = new Person();
        EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new AddUsualDriver("Добавяне на обичаен водач", newUsualDriver).setVisible(true);
            }
        });
    }

    @Action
    public void clearAll() {
        initComponents();
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel AddNewPolicyPanel;
    private javax.swing.JButton AddScannedDocButton;
    private javax.swing.JComboBox PTP;
    private javax.swing.JButton SaveToDBButton;
    private javax.swing.JButton addButton;
    private javax.swing.JTextField adress;
    private javax.swing.JPanel backupPanel;
    private javax.swing.JTextField city;
    private javax.swing.JTextField company;
    private javax.swing.JTextField companyName;
    private javax.swing.JLabel companyNameLabel;
    private javax.swing.JLabel companyNameLabel1;
    private javax.swing.JTextField contractor;
    private javax.swing.JTextField cubics;
    private javax.swing.JButton dailyReportButton;
    private javax.swing.JSpinner dateOfContract;
    private javax.swing.JTextField driverEgn;
    private javax.swing.JTextField egn;
    private javax.swing.JTextField email;
    private javax.swing.JButton excelExportBrokerSearch;
    private javax.swing.JTable expiringPolicies;
    private javax.swing.JPanel expiringPoliciesPanel;
    private javax.swing.JTextField fullName;
    private javax.swing.JLabel gFondLabel;
    private javax.swing.JButton getRestoringDBDir;
    private javax.swing.JButton getSavingDBDir;
    private javax.swing.JTextField grajdFond;
    private javax.swing.JTextField greenCardNumber;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel31;
    private javax.swing.JLabel jLabel32;
    private javax.swing.JLabel jLabel33;
    private javax.swing.JLabel jLabel34;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator5;
    private javax.swing.JSeparator jSeparator6;
    private javax.swing.JSeparator jSeparator7;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JTextField marka;
    private javax.swing.JTextField model;
    private javax.swing.JButton monthlyReportButton;
    private javax.swing.JTextField numberOfSeats;
    private javax.swing.JComboBox personType;
    private javax.swing.JTextField phone;
    private javax.swing.JTextField policy;
    private javax.swing.JTextField premium;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JPanel queriesPanel;
    private javax.swing.JTable queryByCompanyResults;
    private javax.swing.JTable queryResults;
    private javax.swing.JTextField ramaNumber;
    private javax.swing.JTextField regNumber;
    private javax.swing.JTable reportTable;
    private javax.swing.JPanel reportsPanel;
    private javax.swing.JButton resetFields;
    private javax.swing.JTextField restoreFrom;
    private javax.swing.JButton restoreFromButton;
    private javax.swing.JTable salesResults;
    private javax.swing.JTextField salesSearchCompany;
    private javax.swing.JSpinner salesSearchFromDate;
    private javax.swing.JSpinner salesSearchToDate;
    private javax.swing.JTextField saveTo;
    private javax.swing.JButton searchButton;
    private javax.swing.JButton searchByCompanyButton;
    private javax.swing.JButton searchByCompanyButton1;
    private javax.swing.JSpinner searchFromDate;
    private javax.swing.JSpinner searchТоDate;
    private javax.swing.JButton setUsualDriver;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    private javax.swing.JTextField stickerNumber;
    private javax.swing.JTabbedPane tabbedPane;
    private javax.swing.JTextField tonage;
    private javax.swing.JComboBox typeOfPayment;
    private javax.swing.JSpinner validFrom;
    private javax.swing.JSpinner validTo;
    private javax.swing.JButton weeklyReportButton;
    private javax.swing.JTextField yearMade;
	// End of variables declaration//GEN-END:variables


    class ButtonRenderer extends JButton implements TableCellRenderer {

        public ButtonRenderer() {
            setOpaque(true);
        }

        public Component getTableCellRendererComponent(JTable table, Object value,
                boolean isSelected, boolean hasFocus, int row, int column) {
            if (isSelected) {
                setForeground(table.getSelectionForeground());
                setBackground(table.getSelectionBackground());
                System.out.println("Sending mail to..." + peopleMails[row]);
                InsuranceDAO.sendEmail(peopleMails[row], documents.get(row));
            } else {
                setForeground(table.getForeground());
                setBackground(UIManager.getColor("Button.background"));
            }
            setText("Изпрати емейл");
            return this;
        }
    }

    /**
     * @version 1.0 11/09/98
     */
    class ButtonEditor extends DefaultCellEditor {

        protected JButton button;
        private String label;
        private boolean isPushed;

        public ButtonEditor(JCheckBox checkBox) {
            super(checkBox);
            button = new JButton();
            button.setOpaque(true);
            button.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e) {
                    fireEditingStopped();
                }
            });
        }

        public Component getTableCellEditorComponent(JTable table, Object value,
                boolean isSelected, int row, int column) {
            if (isSelected) {
                button.setForeground(table.getSelectionForeground());
                button.setBackground(table.getSelectionBackground());

            } else {
                button.setForeground(table.getForeground());
                button.setBackground(table.getBackground());
            }
            label = "Изпрати емейл";
            button.setText(label);
            isPushed = true;
            return button;
        }

        public Object getCellEditorValue() {
            isPushed = false;
            return "Изпрати емейл";
        }

        public boolean stopCellEditing() {
            isPushed = false;
            return super.stopCellEditing();
        }

        protected void fireEditingStopped() {
            super.fireEditingStopped();
        }
    }

    @Action
    public void makeDailyReport() {
        makeReportForXDays(1);
    }

    class RightTableCellRenderer extends DefaultTableCellRenderer {

        protected RightTableCellRenderer() {
            setHorizontalAlignment(JLabel.LEFT);
        }
    }

    @Action
    public void getScannedDocument() {
        JFileChooser chooser = new JFileChooser();
        int returnVal = chooser.showOpenDialog(this.mainPanel);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            this.documentPath = chooser.getSelectedFile().getAbsolutePath();
        }
    }

    @Action
    public void saveDB() {
        BackupAndRestore.backupDB(saveTo.getText() + "\\db_backup_" + Calendar.getInstance().get(Calendar.DAY_OF_MONTH));
    }

    @Action
    public void restoreDB() {
        BackupAndRestore.restoreDB(restoreFrom.getText());
    }

    @Action
    public void selectSaveDBLocation() {
        JFileChooser chooser = new JFileChooser();
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        int returnVal = chooser.showOpenDialog(this.mainPanel);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            this.saveTo.setText(chooser.getSelectedFile().getAbsolutePath());
        }
    }

    @Action
    public void setRestoreDBLocation() {
        JFileChooser chooser = new JFileChooser();
        chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
        int returnVal = chooser.showOpenDialog(this.mainPanel);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            this.restoreFrom.setText(chooser.getSelectedFile().getAbsolutePath());
        }
    }

    @Action
    public void searchInstallments() {
        Object[][] tableData = InsuranceDAO.getInstallmentsForDriverWithEgn(driverEgn.getText());
        queryResults.setModel(new javax.swing.table.DefaultTableModel(tableData,
                new String[]{
                    "Номер", "Сума за плащане", "Дата за плащане"
                }));

    }
    
    Object[][] savedData;

    @Action
    public void searchByCompany() {
        Date from = (Date)searchFromDate.getValue();
        Date to = (Date)searchТоDate.getValue();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        savedData = InsuranceDAO.getDataByCompany(company.getText(),df.format(from), df.format(to));
        queryByCompanyResults.setModel(new javax.swing.table.DefaultTableModel(savedData,COL_NAMES_FOR_COMPANY_SEARCH));
    }
    
    
    @Action
    public void searchSales() {
        Date from = (Date)salesSearchFromDate.getValue();
        Date to = (Date)salesSearchToDate.getValue();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        savedData = InsuranceDAO.salesSearch(salesSearchCompany.getText(),df.format(from), df.format(to));
        company.setText(salesSearchCompany.getText());
        salesResults.setModel(new javax.swing.table.DefaultTableModel(savedData,COL_NAMES_FOR_SALES_SEARCH));
    }

    @Action
    public void exportToExcel() {
        if (savedData != null) {
            JFileChooser chooser = new JFileChooser();
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int returnVal = chooser.showOpenDialog(this.mainPanel);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                String filePath = chooser.getSelectedFile().getAbsolutePath()+ "\\" + company.getText() + "_data.xls";
                if ( savedData[0].length == COL_NAMES_FOR_COMPANY_SEARCH.length)
                    InsuranceDAO.exportToExcel(filePath, savedData,COL_NAMES_FOR_COMPANY_SEARCH);
                else
                    InsuranceDAO.exportToExcel(filePath, savedData,COL_NAMES_FOR_SALES_SEARCH);
            }
        }
    }

}
